package com.yao.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yao.system.entity.*;
import com.yao.system.entity.dto.CollectionDTO;
import com.yao.system.entity.dto.UserDTO;
import com.yao.system.mapper.JobCollectionMapper;
import com.yao.system.service.IJobCollectionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yao.system.service.IJobResumeService;
import com.yao.system.service.IJobService;
import com.yao.system.service.IResumeService;
import com.yao.system.util.UserContext;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 霖
 * @since 2024-04-22
 */
@Service
@RequiredArgsConstructor
public class JobCollectionServiceImpl extends ServiceImpl<JobCollectionMapper, JobCollection> implements IJobCollectionService {


    /**
     * 收藏或取消收藏岗位
     *
     * @param dto
     * @return
     */
    @Override
    public Result collection(CollectionDTO dto) {
        UserDTO user = UserContext.getUser();

        JobCollection collection = new JobCollection();
        collection.setJobId(dto.getJobId());
        collection.setUserId(user.getId());
        if (dto.getType() == 0) {
            LambdaQueryWrapper<JobCollection> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(JobCollection::getUserId, collection.getUserId())
                    .eq(JobCollection::getJobId, collection.getJobId());
            remove(queryWrapper);
            return Result.ok("取消收藏");
        }
        save(collection);
        return Result.ok("收藏成功");
    }
}
